package org.abettor.tanqiu.gameloop.object;

import com.badlogic.gdx.math.Vector2;

/**
 * 长方形地图
 * 
 * @author jzh
 * 
 */
public class BallMapSquarePart extends BallMapPart {
	public static final int TYPE_HORIZONTAL = 0;// 水平放置
	public static final int TYPE_VERTICAL = 1;// 垂直放置
	public static final int TYPE_LEFTSLANT = 2;// 向左倾斜
	public static final int TYPE_RIGHTSLANT = 3;// 向右倾斜

	//private float width, height;// 正方形地图的宽度和高度
	private int type;// 正方形地图的类型,垂直放置，水平放置
	private Vector2 begin, end;// 起始坐标,终点坐标
	public BallMapSquarePart(int type,Vector2 begin,Vector2 end){
		this.type = type;
		this.begin = begin;
		this.end = end;
	}
	/**
	 * 长条的长度
	 * @return
	 */
	public float getLenth(){
		return begin.dst(end);
	}
	@Override
	public Vector2 nextStep(Vector2 start, int step) {
		Vector2 retVector = new Vector2();
		float x, y;
		switch (type) {
		case TYPE_HORIZONTAL:
			if (end.x > begin.x) {
				x = start.x + step;
				if (x > end.x) {
					return null;
				}
			} else {
				x = start.x - step;
				if (x < end.x) {
					return null;
				}
			}
			retVector.x = x;
			retVector.y = begin.y;
			return retVector;
		case TYPE_VERTICAL:
			if (end.y > begin.y) {
				y = start.y + step;
				if (y > end.y) {
					return null;
				}
			} else {
				y = start.y - step;
				if (y < end.y) {
					return null;
				}
			}
			retVector.x = begin.x;
			retVector.y = y;
			return retVector;
		case TYPE_LEFTSLANT:
			if (end.x > begin.x) {
				y = start.y + step;
				x = start.x + step;
				if (x > end.x) {
					return null;
				}
			} else {
				y = start.y - step;
				x = start.x - step;
				if (x < end.x) {
					return null;
				}
			}
			retVector.x = x;
			retVector.y = y;
			return retVector;
		case TYPE_RIGHTSLANT:
			if (end.x > begin.x) {
				y = start.y - step;
				x = start.x + step;
				if (x > end.x) {
					return null;
				}
			} else {
				y = start.y + step;
				x = start.x - step;
				if (x < end.x) {
					return null;
				}
			}
			retVector.x = x;
			retVector.y = y;
			return retVector;
		}
		return null;
	}

	public int getType() {
		return type;
	}

	public void setType(int type) {
		this.type = type;
	}

	public Vector2 getBegin() {
		return begin;
	}

	public void setBegin(Vector2 begin) {
		this.begin = begin;
	}

	public Vector2 getEnd() {
		return end;
	}

	public void setEnd(Vector2 end) {
		this.end = end;
	}
}
